package sesja;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

public class sesjaimpl implements sesja_interface {

	private FacesContext ctx;
	private static HttpSession session;
	private static String str_sessionId=null;
	public static final String[][] array=
	{{"n","menu_nauczyciel"},{"s","menu_student"},{"a","menu_admin"}};
	
	public String F_getStr_sessionId() {
		return str_sessionId;
	}

	public void setStr_sessionId(String str_sessionId) {
		this.str_sessionId = str_sessionId;
	}
	
	private void wykonaj_cos(){};
	protected void wykonaj_cos_protected(){};
	public int delete_idsesja(String sesja, int user) {
		return 0;
	}

	public sesjaimpl(){
		ctx = FacesContext.getCurrentInstance();
		session = (HttpSession) ctx.getExternalContext().getSession(true);
		str_sessionId=session.getId();
		//only for test
		//this.str_sessionId="1";
	}
	
	public int F_sprawdz_aktywnoscsesji(String sesja_z_bazy) {
		if(this.str_sessionId==null)
			return -1;
		if (this.str_sessionId==sesja_z_bazy)
			return 1;
		else
			return 0;
	}
	public void F_wstaw_prawa(String prawo){
		session.setAttribute("prawa",prawo);
	}
	public static void F_insert_value_into_session(String name_value,String value){
		System.out.println("wprowadzanie");
		session.setAttribute(name_value,value);
	}
	public static String F_get_value_into_session(String name_value){
		return session.getAttribute(name_value).toString();
	}
	public static void F_delete_value_from_session(String name_value){
		session.removeAttribute(name_value);
	}
}
